package com.gopay.scheduler.job;

import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.jobmonitor.impl.JobMonitorHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务监控Job
 * 
 * @JobMonitorJob.java
 * @author fanghw
 * @2015年5月8日 上午11:38:56 www.gopay.com.cn Inc.All rights reserved.
 */
public class JobMonitorJob extends GopayBaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource(name = "jobMonitorHelper")
    private JobMonitorHelper jobMonitorHelper;

    @Override
    public void doJobInternal() {
        //查询异常状态的Job
		List<String> jobList = jobMonitorHelper.queryErrorJob();
        //封装通知内容
        if(jobList.size()>0){
            StringBuilder sb=new StringBuilder();
            sb.append("错误状态的Job有"+jobList.size()+"个,名称如下:\r\n");
            int count=1;
            for(String n:jobList) {
                sb.append(count++).append(". ");
                sb.append(n).append("\r\n");
            }
                        
            logger.error(sb.toString());
            //微信通知
            logger.error("-----weixin push start");
            boolean pushResult=jobMonitorHelper.sendWeixin(sb.toString());
            logger.error("-----weixin pushResult="+pushResult);
        }
    }
}